package com.loukou.lkt.lkt.dao;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import com.loukou.lkt.lkt.entity.PoPurchaseReturnOrder;

public interface PoPurchaseReturnOrderDao extends CrudRepository<PoPurchaseReturnOrder,Integer>,JpaSpecificationExecutor<PoPurchaseReturnOrder>{
	
	PoPurchaseReturnOrder findByOrderReturnCode(String orderReturnCode);
	
	PoPurchaseReturnOrder findById(int id);

	@Modifying
	@Transactional
	@Query("update PoPurchaseReturnOrder set stockOutorderId = ?2,actualReturntime = ?3,orderState = ?4,deliveryUserName = ?5,deliveryTime = ?6 where id = ?1")
	void updatePoPurchaseReturnOrderForApi(int id,int stockOutorderId,Date actualReturntime,int orderState,String deliveryUserName,Date deliveryTime);


	@Modifying
	@Transactional
	@Query("update PoPurchaseReturnOrder set warehouseId = ?2, planReturntime=?3,actualArrivetime = ?4,reason = ?5,"
			+ "address = ?6, remark=?7  where id = ?1")
	int updatePoPurchaseReturnOrderForEdit(int returnOrderId, int warehouseId,
			Date planReturntime, Date actualArrivetime, String reason,
			String address, String remark);

	List<PoPurchaseReturnOrder> findByOrderState(int orderState);
	
	@Modifying
	@Transactional
	@Query("update PoPurchaseReturnOrder set orderState = ?1 where id = ?1")
	int updateOrderStateById(int state, int purchaseReturnOrderId);

}
